<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Redis;

class Bank extends Model
{
    protected $table = 'sp_bank';
    protected $primaryKey = 'id';
    public $timestamps = false;

    public function getAll()
    {
//        $bankList=Redis::get('bankList');
//        if($bankList){
//            return json_decode($bankList,true);
//        }
        $bank= $this
            ->where('type', 3)
            ->orderBy('id', 'asc')
            ->select('id', 'bank_name','bank_code')
            ->get();
        $bank = $bank ? $bank->toArray() : [];
        $data=[];
        foreach ($bank as $ra) {
            $data[]=$ra['bank_name'];
        }
        Redis::set('bankList', json_encode($bank));
        return $data;
    }


    public static function detail($id)
    {
        return (new self())::where('bank_name',$id)->first()->toArray();
    }

    public static function baoDetail($id)
    {
        return (new self())::where('bank_name',$id)->where('type',2)->first()->toArray();
    }

    public static function kuaiDetail($id)
    {
        return (new self())::where('bank_name',$id)->where('type',3)->first();
    }

}
